﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace SmartTextBlockDemo
{
    public partial class MainPage : PhoneApplicationPage
    {

        #region TextString (DependencyProperty)

        public string TextString
        {
            get { return (string)GetValue(TextStringProperty); }
            set { SetValue(TextStringProperty, value); }
        }
        public static readonly DependencyProperty TextStringProperty =
            DependencyProperty.Register("TextString", typeof(string), typeof(MainPage),
              new PropertyMetadata(string.Empty));

        #endregion


        // Constructor
        public MainPage()
        {
            TextString = "enter text in textbox above and see it turned all smart here";
            InitializeComponent();
            PhoneApplicationService.Current.Deactivated += new EventHandler<DeactivatedEventArgs>(Current_Deactivated);
            Loaded += new RoutedEventHandler(MainPage_Loaded);

        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (PhoneApplicationService.Current.State.Keys.Contains("s"))
            {
                TextString = PhoneApplicationService.Current.State["s"] as string;
            }
        }

        void Current_Deactivated(object sender, DeactivatedEventArgs e)
        {
            PhoneApplicationService.Current.State["s"] = TextString;
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            TextString = TestInput.Text;
        }

        private void Uri_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/InApplicationBrowser.xaml?uri="+sender.ToString(), UriKind.RelativeOrAbsolute));
        }
    }
}